// 数据字典
const express = require("express");
const apiRouter = express.Router();
const fs = require("fs");
const writeData = require("../../db/module/writeData");
const readData = require("../../db/module/readData");
const delData = require("../../db/module/delData");
const jwt = require("jsonwebtoken");
const { default: disposeDatabase } = require("../../models/relevanceDatabase");
const secretKey = "Aa2317770710"; //生成token的密钥

// 新增数据字典
apiRouter.post("/addDataDictionary", async (req, res) => {
  try {
    const params = req.body;
    let result = await writeData(params, "dataDictionary");
    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});

// 查询数据字典列表
apiRouter.post("/getDataDictionary", async (req, res) => {
  try {
    const params = req.body;
    let result = await readData(params, "dataDictionary");
    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});

// 删除数据字典
apiRouter.post("/delDataDictionary", async (req, res) => {
  try {
    const params = req.body;
    let result = await delData(params, "dataDictionary");
    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});

// 新增字典项
apiRouter.post("/addDictionaryItem", async (req, res) => {
  try {
    const params = req.body;
    let result = await writeData(params, "dictionaryItem");
    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});

// 获取字典项列表
apiRouter.post("/getDictionaryItem", async (req, res) => {
  try {
    const params = req.body;

    let result = await readData(params, "dictionaryItem");

    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});

// 删除字典项
apiRouter.post("/delDictionaryItem", async (req, res) => {
  try {
    const params = req.body;
    let result = await delData(params, "dictionaryItem");
    res.send(result);
  } catch (error) {
    res.send({
      code: 50000,
      msg: error,
    });
  }
});



module.exports = apiRouter;
